import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { LoginService } from '../../services/login.service';


class LoginInfo {
  email: string;
  password: string;
  code: string;
}

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  params: LoginInfo = {
    email: '',
    password: '',
    code: ''
  };

  constructor(private router: Router, private loginService: LoginService, ) { }

  ngOnInit() {
  }

  onSubmit() {
    console.log('ss', this.params);
    const { email, password, code } = this.params;
    this.loginService.login({ username: email, pass: password }).subscribe((res) => {
      if (res && res.code === 200) {
        window.localStorage.setItem('userinfo', JSON.stringify({ username: '店小二' }));
        this.router.navigate(['/users']);
        this.loginService.logInit();
        console.log('ajax登陆成功');
      } else {
        alert(res.msg);
      }
    });
  }
}
